package org.accp.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.accp.dao.ComplaintDao;
import org.accp.pojo.Complaint;
import org.accp.pojo.Hisrole;
import org.accp.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/complaint")
@CrossOrigin("*")
public class ComplaintController {
    @Autowired
    private ComplaintDao complaintDao;

    public void setComplaintDao(ComplaintDao complaintDao) {
        this.complaintDao = complaintDao;
    }

    @RequestMapping("/list")
    @ResponseBody
    public ResponseResult<List<Complaint>> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit, Complaint condition) throws Exception {
            Page<Complaint> pager = PageHelper.startPage(page, limit);
            List<Complaint> list = complaintDao.getConditionList(condition);
            return new ResponseResult(pager.getTotal(),list);
    }
    @RequestMapping("/batchDelete")
    @ResponseBody
    public ResponseResult batchDelete(Integer[] id) throws Exception{
        complaintDao.batchDelete(id);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseResult delete(int id) throws Exception{
        complaintDao.delete(id);
        return ResponseResult.createSuccessResult();
    }

    @RequestMapping("/add")
    @ResponseBody
    public ResponseResult add(Complaint complaint) throws Exception{
        complaintDao.add(complaint);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/adds")
    @ResponseBody
    public ResponseResult adds(Complaint complaint) throws Exception{
        complaintDao.adds(complaint);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/update")
    @ResponseBody
    public ResponseResult update(Complaint complaint ) throws Exception{
        complaintDao.update(complaint);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/get")
    @ResponseBody
    public ResponseResult get(Integer id) throws Exception{
        complaintDao.get(id);
        return ResponseResult.createSuccessResult();
    }
}

